package rmiclient;

import handler.CallHandler;

import java.io.IOException;

import net.Client;
import util.AppFeatures;

public class Service {
	private static AppFeatures serviceInstance = null;

	static Client client = null;
	static CallHandler callHandler = new CallHandler();

	private final static int DEFAULT_PORT_NUMBER = 1099;
	private static int port = DEFAULT_PORT_NUMBER;

	private static String serverLocation = "localhost";

	/**
	 * @return the serviceInstance
	 */
	public static AppFeatures getServiceInstance() {
		if (serviceInstance == null) {

			try {
				client = new Client(serverLocation, port, callHandler);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			serviceInstance = (AppFeatures) client.getGlobal(AppFeatures.class);
		}
		return serviceInstance;
	}

	public static void setServiceProperties(int port, String serverLocation) {

		if (serverLocation != null) {
			Service.serverLocation = serverLocation;
		}
		serviceInstance = null;
	}

	protected Service() {

	}

	public static String getServerLocation() {
		return serverLocation;
	}

	public static int getPort() {
		return port;
	}
}
